package org.jeecg.modules.cosmetic.controller;

import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.cosmetic.handler.IngredientHandler;
import org.jeecg.modules.cosmetic.model.dto.IngredientContentDTO;
import org.jeecg.modules.cosmetic.model.dto.IngredientEvaluateDTO;
import org.jeecg.modules.cosmetic.model.dto.IngredientRiskDTO;
import org.jeecg.modules.cosmetic.model.vo.FormulaRiskUpdateVO;
import org.jeecg.modules.cosmetic.model.vo.IngredientUpdateVO;
import org.jeecg.modules.cosmetic.utils.MyValidateUtil;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: 实际成分
 * @Author: jeecg-boot
 * @Date: 2022-06-30
 * @Version: V1.0
 */
@Api(tags = "实际成分")
@RestController
@RequestMapping("/api/ingredient")
@Slf4j
public class TSecurityEvaluationController {

    @Resource
    private IngredientHandler ingredientHandler;

    @ApiOperation(value = "产品实际成分含量列表", notes = "产品实际成分含量列表")
    @GetMapping(value = "/purity_query")
    public Result<List<IngredientContentDTO>> purityQuery(@RequestParam(value = "productId", required = true) Long productId) {
        return ingredientHandler.getActualPurityList(productId);
    }

    @ApiOperation(value = "各成分安全评估列表", notes = "各成分安全评估列表")
    @GetMapping(value = "/security_evaluation_query")
    public Result<List<IngredientEvaluateDTO>> securityEvaluationQuery(@RequestParam(value = "productId", required = true) Long productId) {
        return ingredientHandler.queryIngredientEvaluateList(productId);
    }

    @ApiOperation(value = "成分评估详情", notes = "成分评估详情")
    @GetMapping(value = "/detail")
    public Result<IngredientEvaluateDTO> detail(@RequestParam(value = "id", required = true) Long id) {
        return ingredientHandler.queryIngredientEvaluateDetail(id);
    }

    @ApiOperation(value = "成分危害物质查询", notes = "成分危害物质查询")
    @GetMapping(value = "/risk_query")
    public Result<List<IngredientRiskDTO>> riskQuery(@RequestParam(value = "productId", required = true) Long productId) {
        return ingredientHandler.queryIngredientRiskList(productId);
    }

    @ApiOperation(value = "更新成分信息", notes = "更新成分信息")
    @PostMapping(value = "/modify")
    public Result<?> modify(@RequestBody IngredientUpdateVO vo) {
        MyValidateUtil.validThrow(vo);
        return ingredientHandler.updateIngredientByPrimary(vo);
    }

    @ApiOperation(value = "风险危害物质详情", notes = "风险危害物质详情")
    @GetMapping(value = "/risk_detail")
    public Result<IngredientRiskDTO> riskDetail(@RequestParam(value = "id", required = true) Long id) {
        return ingredientHandler.queryIngredientRiskDetail(id);
    }

    @ApiOperation(value = "风险危害物质修改", notes = "风险危害物质修改")
    @PostMapping(value = "/risk_modify")
    public Result<?> riskModify(@RequestBody List<FormulaRiskUpdateVO> vo) {
        MyValidateUtil.validThrow(vo);
        return ingredientHandler.updateFormulaRiskByPrimary(vo);
    }
}
